﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductCommandHandler
{
    public class ProductCreateCommandHandler : IRequestHandler<ProductCreateCommand, int>
    {
        private readonly IProductRepository _productRepository;

        public ProductCreateCommandHandler(IProductRepository productRepository)
        {
            _productRepository = productRepository;
        }
        /// <summary>
        /// 产品管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductCreateCommand request, CancellationToken cancellationToken)
        {
            var list = await _productRepository.Add(new Domain.Product.ProductInfo()
            {
                ProductNo = request.ProductNo,
                ProductName = request.ProductName,
                ManuNo = request.ManuNo,
                InsideNo = request.InsideNo,
                UnitId = request.UnitId,
                ProductTypeId = request.ProductTypeId,
                GoOnline = request.GoOnline,
                Online = request.Online,
                ProductSpec=request.ProductSpec,
                ProductPrice=request.ProductPrice,
                WarehouseId=request.WarehouseId,
                BinLocationId=request.BinLocationId,
                VendorId=request.VendorId,
                ClientId=request.ClientId,
                ProductDesc=request.ProductDesc,
                ProductWrap="单包",
                ProductWeight="50g",
                officeId = "10086",
                userid = 10010,
                IsDelete = false,
                CreateName = "admin",
                CreateTime = DateTime.Now,
            });

            return list;
        }
    }
}
